Skip to content

refactor: reduce complexity of execute_impl in create_work_item.rs#1509

Merged
jamesadevine merged 1 commit into
mainfrom
refactor/reduce-complexity-create-work-item-9282d502e72e3878
Jul 15, 2026
Merged

refactor: reduce complexity of execute_impl in create_work_item.rs#1509
jamesadevine merged 1 commit into
mainfrom
refactor/reduce-complexity-create-work-item-9282d502e72e3878

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

execute_impl in src/safe_outputs/create_work_item.rs had a nesting depth of 7 — driven by the artifact-link resolution block, which stacked four layers of control flow:

if config.artifact_link.enabled {
    if let Some(repo_name) = repo_name {
        match repo_id {
            None => match resolve_repository_id(...).await {
                Err(e) => return Ok(failure),
                ...

This made the artifact-link path hard to read and test in isolation.

What changed

Extracted a new async helper maybe_build_artifact_link_op that encapsulates the full artifact-link resolution logic and returns a tri-state:

  • Ok(None) — linking disabled
  • Ok(Some((op, message))) — op built successfully
  • Err(ExecutionResult) — caller should short-circuit with a failure

The main execute_impl body now calls it with a single match on three arms, reducing the nesting depth from 7 → 4 and making the execution path linear and easy to follow.

Verification

  • All tests pass (cargo test)
  • Clippy clean (cargo clippy --all-targets --all-features)
  • No behaviour changes — the helper faithfully reproduces the original branching logic

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · 57.7 AIC · ⌖ 12.2 AIC · ⊞ 7.2K ·

Extract maybe_build_artifact_link_op helper to eliminate deep
nesting in the artifact-link resolution block. The nested
if-enabled → if-repo_name → match repo_id → match resolve
chain (4 levels of nesting) is now a single call that returns
Ok(None), Ok(Some((op,msg))), or Err(failure) — reducing the
nesting depth of execute_impl from 7 to 4 and making the main
execution path linear and easy to follow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamesadevine
jamesadevine marked this pull request as ready for review July 15, 2026 09:47
@jamesadevine
jamesadevine merged commit 06bd5fa into main Jul 15, 2026
21 checks passed
@jamesadevine
jamesadevine deleted the refactor/reduce-complexity-create-work-item-9282d502e72e3878 branch July 15, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant